package net.lab1024.smartadmin.module.business.gearboxEfficiency.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.lab1024.smartadmin.common.domain.PageResultDTO;
import net.lab1024.smartadmin.common.domain.ResponseDTO;
import net.lab1024.smartadmin.module.business.gearboxEfficiency.dao.GearboxEfficiencyDao;
import net.lab1024.smartadmin.module.business.gearboxEfficiency.domain.dto.GearboxEfficiencyAddDTO;
import net.lab1024.smartadmin.module.business.gearboxEfficiency.domain.dto.GearboxEfficiencyQueryDTO;
import net.lab1024.smartadmin.module.business.gearboxEfficiency.domain.dto.GearboxEfficiencyUpdateDTO;
import net.lab1024.smartadmin.module.business.gearboxEfficiency.domain.entity.GearboxEfficiencyEntity;
import net.lab1024.smartadmin.module.business.gearboxEfficiency.domain.vo.GearboxEfficiencyExcelVO;
import net.lab1024.smartadmin.module.business.gearboxEfficiency.domain.vo.GearboxEfficiencyVO;
import net.lab1024.smartadmin.util.SmartBeanUtil;
import net.lab1024.smartadmin.util.SmartPageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * [ 变速箱效率MAP ]
 *
 * @author wuhq
 * @version 1.0
 * @company 变速箱效率MAP
 * @copyright (c)  变速箱效率MAPInc. All rights reserved.
 * @date 2021-11-21 19:18:38
 * @since JDK1.8
 */
@Service
public class GearboxEfficiencyService {

    @Autowired
    private GearboxEfficiencyDao gearboxEfficiencyDao;

    /**
     * 根据id查询
     */
    public GearboxEfficiencyEntity getById(Long id){
        return  gearboxEfficiencyDao.selectById(id);
    }

    /**
     * 分页查询
     * @author wuhq
     * @date 2021-11-21 19:18:38
     */
    public ResponseDTO<PageResultDTO<GearboxEfficiencyVO>> queryByPage(GearboxEfficiencyQueryDTO queryDTO) {
        Page page = SmartPageUtil.convert2QueryPage(queryDTO);
        IPage<GearboxEfficiencyVO> voList = gearboxEfficiencyDao.queryByPage(page, queryDTO);
        PageResultDTO<GearboxEfficiencyVO> pageResultDTO = SmartPageUtil.convert2PageResult(voList);
        return ResponseDTO.succData(pageResultDTO);
    }

    /**
     * 添加
     * @author wuhq
     * @date 2021-11-21 19:18:38
     */
    public ResponseDTO<String> add(GearboxEfficiencyAddDTO addDTO) {
        GearboxEfficiencyEntity entity = SmartBeanUtil.copy(addDTO, GearboxEfficiencyEntity.class);
        gearboxEfficiencyDao.insert(entity);
        return ResponseDTO.succ();
    }

    /**
     * 编辑
     * @author wuhq
     * @date 2021-11-21 19:18:38
     */
    @Transactional(rollbackFor = Exception.class)
    public ResponseDTO<String> update(GearboxEfficiencyUpdateDTO updateDTO) {
        GearboxEfficiencyEntity entity = SmartBeanUtil.copy(updateDTO, GearboxEfficiencyEntity.class);
        gearboxEfficiencyDao.updateById(entity);
        return ResponseDTO.succ();
    }

    /**
     * 删除
     * @author wuhq
     * @date 2021-11-21 19:18:38
     */
    @Transactional(rollbackFor = Exception.class)
    public ResponseDTO<String> deleteByIds(List<Long> idList) {
        gearboxEfficiencyDao.deleteByIdList(idList);
        return ResponseDTO.succ();
    }

    /**
     * 查询全部导出对象
     * @author wuhq
     * @date 2021-11-21 19:18:38
     */
    public List<GearboxEfficiencyExcelVO> queryAllExportData(GearboxEfficiencyQueryDTO queryDTO) {
        return gearboxEfficiencyDao.queryAllExportData( queryDTO);
    }

    /**
     * 批量查询导出对象
     * @author wuhq
     * @date 2021-11-21 19:18:38
     */
    public List<GearboxEfficiencyExcelVO> queryBatchExportData(List<Long> idList) {
        return gearboxEfficiencyDao.queryBatchExportData(idList);
    }

    public void delByGearboxId(Long gearboxId) {
        LambdaQueryWrapper<GearboxEfficiencyEntity> queryWrapper = new LambdaQueryWrapper<GearboxEfficiencyEntity>();
        queryWrapper.eq(GearboxEfficiencyEntity::getGearboxId, gearboxId);
        gearboxEfficiencyDao.delete(queryWrapper);
    }

    public GearboxEfficiencyEntity getByGearboxId(Long gearboxId) {
        LambdaQueryWrapper<GearboxEfficiencyEntity> queryWrapper = new LambdaQueryWrapper<GearboxEfficiencyEntity>();
        queryWrapper.eq(GearboxEfficiencyEntity::getGearboxId, gearboxId);
        return gearboxEfficiencyDao.selectOne(queryWrapper);
    }

}
